package chai.components
{
	import chai.model.User;
	
	import flash.utils.*;
	
	import mx.collections.ArrayCollection;
	
	public class MiniFriendChooserModel
	{
		public function MiniFriendChooserModel():void
		{
			otherFriends = new ArrayCollection();
			selectedFriends = new ArrayCollection();
			quickFriends = new ArrayCollection();
			
			otherFriends.sort = User.displayNameSort;
			selectedFriends.sort = User.displayNameSort;
		}
		
		[Bindable]
		public var otherFriends:ArrayCollection;
		
		[Bindable]
		public var selectedFriends:ArrayCollection;
		
		[Bindable]
		public var quickFriends:ArrayCollection;
		
		public function setFriendSelected(friend:User, selected:Boolean):void
		{
			var exists:Boolean = -1 != selectedFriends.getItemIndex(friend);
		 	if (selected) {
				if (!exists) {
					selectedFriends.addItem(friend);
					if (-1 == quickFriends.getItemIndex(friend)) {
						quickFriends.addItem(friend);
						otherFriends.removeItemAt(otherFriends.getItemIndex(friend)); 
					}
				}
			} else {
				if (exists) {
					selectedFriends.removeItemAt(selectedFriends.getItemIndex(friend));
				}
			}
		}
	}
}